from spleeter.separator import Separator
import os


def separate_audio(input_audio, output_directory):
    separator = Separator('spleeter:2stems')  # 使用2stems模型分离人声和伴奏
    separator.separate_to_file(input_audio, output_directory)


def main():
    input_audio_path = 'buff/2_origin_wav/1_CSdpk6NzvhY.wav'  # 输入音频文件路径
    output_directory = 'buff/2_zmic_wav/'  # 输出分离后音轨的目录

    separate_audio(input_audio_path, output_directory)


def traverse_directory(directory):
    for root, dirs, files in os.walk(directory):
        # 遍历目录中的文件
        for file in files:
            file_path = os.path.join(root, file)

            # 在这里执行文件操作，例如打印文件路径或进行其他处理
            output_directory = 'buff/2_zmic_wav/'  # 输出分离后音轨的目录
            separate_audio(file_path, output_directory)


os.environ['PATH'] = '/usr/local/bin:' + os.environ['PATH']  # 添加 ffmpeg 路径到环境变量中
# 指定要遍历的目录路径
directory_path = 'buff/2_origin_wav'

if __name__ == '__main__':
    traverse_directory(directory_path)
# 调用遍历函数
